/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mb.mbpart.object;

import mb.config.DatabaseConfig;
import net.sf.json.JSONObject;
import org.json.simple.JSONValue;

/**
 *
 * @author thanh.nguyenchi
 */
public class NewsObject {
    // define table
    public String STR_C_NEWS_ID = "News_ID";
    public String STR_C_TITLE = "Title";
    public String STR_C_ADDRESS = "Address";
    public String STR_C_TEASER = "Teaser";
    public String STR_C_CONTENT = "Content";
    public String STR_C_AVATAR = "Avatar";
    public String STR_C_LATITUDE = "Latitude";
    public String STR_C_LONGITUDE = "Longitude";
    public String STR_C_FROM_DATE = "FromDate";
    public String STR_C_TO_DATE = "DueDate";
    public String STR_C_PHONE = "Phone";
    public String STR_C_LINK = "OrigLink";
    public String STR_C_TYPE = "Cate_ID";
   
    
    //public field
    public long C_NEWS_ID;
    public String C_TITLE;    
    public String C_ADDRESS;
    public String C_TEASER;
    public String C_CONTENT;
    public String C_AVATAR;
    public double C_LATITUDE;
    public double C_LONGITUDE;
    public String C_FROM_DATE;
    public String C_TO_DATE;   
    public String C_PHONE;  
    public String C_LINK;
    public long C_TYPE;
    
    public NewsObject(){}
    
    
    public String toProJson(){
        JSONObject objRecv = new JSONObject();
        objRecv.put(STR_C_NEWS_ID,new Long(this.C_NEWS_ID));
        objRecv.put(STR_C_TITLE, this.C_TITLE);
        objRecv.put(STR_C_TEASER,this.C_TEASER);
        objRecv.put(STR_C_ADDRESS,this.C_ADDRESS);
        objRecv.put(STR_C_CONTENT,this.C_CONTENT);
        objRecv.put(STR_C_AVATAR,this.C_AVATAR);
        objRecv.put(STR_C_LATITUDE, new Double(this.C_LATITUDE));
        objRecv.put(STR_C_LONGITUDE, new Double(this.C_LONGITUDE));   
        objRecv.put(STR_C_FROM_DATE, this.C_FROM_DATE);
        objRecv.put(STR_C_TO_DATE, this.C_TO_DATE);
        objRecv.put(STR_C_PHONE, this.C_PHONE);
        objRecv.put(STR_C_LINK, this.C_LINK);
        objRecv.put(STR_C_TYPE, this.C_TYPE);
        return JSONValue.toJSONString(objRecv);
    }
    
    public String toNewsJson(){
        JSONObject objRecv = new JSONObject();
        objRecv.put(STR_C_NEWS_ID,new Long(this.C_NEWS_ID));
        objRecv.put(STR_C_TITLE, this.C_TITLE);
        objRecv.put(STR_C_ADDRESS,this.C_ADDRESS);
        objRecv.put(STR_C_TEASER,this.C_TEASER);
        objRecv.put(STR_C_CONTENT,this.C_CONTENT);
        objRecv.put(STR_C_AVATAR,this.C_AVATAR);
        objRecv.put(STR_C_LATITUDE, new Double(this.C_LATITUDE));
        objRecv.put(STR_C_LONGITUDE, new Double(this.C_LONGITUDE));   
        objRecv.put(STR_C_FROM_DATE, this.C_FROM_DATE);
        objRecv.put(STR_C_TO_DATE, this.C_TO_DATE);
        objRecv.put(STR_C_PHONE, this.C_PHONE);
        objRecv.put(STR_C_LINK, this.C_LINK);
        objRecv.put(STR_C_TYPE, new Long(this.C_TYPE));
        return JSONValue.toJSONString(objRecv);
    }
    
    public String toJson(long id,DatabaseConfig objConfig){
        if (id == objConfig.getPromotion_id()){
            return toProJson();
        }
        else{
            return toNewsJson();
        }
        
    }
}
